package com.design.boot.controller;

import com.design.boot.common.exception.BaseException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author kakayubei
 * @description
 * @date 2021/7/31 12:10
 */
@ControllerAdvice
public class ExceptionController {

    @ExceptionHandler({ BaseException.class }) // 当发生BaseException类(及其子类)的异常时，进入该方法
    public ModelAndView baseExceptionHandler(BaseException e) {
        ModelAndView mv = new ModelAndView();
        mv.addObject("code", e.getCode());
        mv.addObject("message", e.getMessage());
        mv.setViewName("myerror");// 跳转到resource/templates/myerror.html页面
        return mv;
    }

}
